package com.example.onlinemusic.mapper;

import com.example.onlinemusic.model.Music;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface LoveMusicMapper {
    // 根据用户id 以及音乐id 查询收藏的歌曲
    @Select("select * from lovemusic where user_id=#{userId} and music_id=#{musicId}")
    Music findLoveMusicByMusicIdAndUserId(Integer userId,Integer musicId);

    @Insert("insert into lovemusic(user_id,music_id) values(#{userId},#{musicId})")
    boolean insertLoveMusic(Integer userId, Integer musicId);

    /**
     * 查询这个用户收藏过的所有音乐
     * @param userId
     * @return
     */
    @Select("select m.* from lovemusic lm,music m where m.id=lm.music_id and lm.user_id=#{userId}")
    List<Music> findLoveMusicByUserId(int userId);

    /**
     * 查询当前用户，指定为 musicName 的音乐，支持模糊查询
     * @param musicName
     * @param userId
     * @return
     */
    @Select("select m.* from lovemusic lm,music m where m.id=lm.music_id and lm.user_id=#{userId} and title like concat('%',#{musicName},'%')" )
    List<Music> findLoveMusicByKeyAndUID(String musicName,int userId);

    @Delete("delete from lovemusic where user_id=#{userId} and music_id=#{musicId}")
    int cancelLoveMusic(Integer userId, Integer musicId);

    @Delete("delete from lovemusic where music_id=#{musicId}")
    int deleteLoveMusicByMusicId(int musicId);
}
